<template>
<Modal title="编辑数据源"
        v-model="modalShow"
        :on-ok="save"
        :on-cancel="cancel"
        :auto-close="false"
        :mask-closable="false">
    <Spin size="large" fix v-if="loading"></Spin> <!-- 加载动画 -->
    <Form ref="editDsForm" :model="datasource" :label-width="95" label-position="right">
        <Form-item
            label="数据源名称"
            prop="datasourceName"
            :rules="{required: true, message: '请输入数据源名称！'}">
            <Input placeholder="数据源名称" clearable style="width: 98%" v-model="datasource.datasourceName" />
        </Form-item>
        <Form-item label="数据源状态" prop="status"
            :rules="{required: true, message: '请选择状态！'}">
            <RadioGroup v-model="datasource.status" type="button">
                <Radio :label="1">启用</Radio>
                <Radio :label="0">禁用</Radio>
            </RadioGroup>
        </Form-item>
        <Form-item label="描述" prop="remark">
            <Input placeholder="描述" type="textarea" clearable style="width: 98%" v-model="datasource.remark" />
        </Form-item>
    </Form>
</Modal>
</template>

<script>
import getData from 'getData'
import util    from 'util'

export default {
    /**
     * @description 新增连接弹窗
     * @author zhangyuntao
     */

    name: 'EditDatasource',

    components: {

    },

    data () {
        return {
            loading: false,
            modalShow: false,
            btnLoading: false,
            datasource: {}
        }
    },

    methods: {
        show(data) {
            this.$set(this, 'datasource', util.util.cloneObj(data));
            this.modalShow = true;
        },

        save() {
            this.$refs.editDsForm.validate( valid => {
                if (valid) {
                    this.loading = true;
                    getData.post('saveDatasource', this.datasource).then(res => {
                        this.loading = false;
                        if (res.status == 200 && res.data.code == '000') {
                            this.$Message.success('更新数据源成功！');
                            this.$emit('refresh');
                        }
                    })
                }
            });
        },
        cancel() {
            this.$refs.editDsForm.resetFields();
            this.modalShow = false;
        }
    }
}
</script>

<style lang="less">

</style>
